package root;

import java.io.*;
//import java.math.*;

public class Main {

	public static void main(String[] Args) throws IOException {
		
		final double a = Math.pow(2, 60);  //bepaal wortel van
		final double n = 2000000.0;  //bepaal soveelste wortel
		double aRoot = a/n; //die wortel
		int i = 0;
		final double acc = 0.00000000009;
		int c = 0;
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		System.out.println("0) newton x 5\n1) fast newton \n2) normal newton");
		
		c = Integer.parseInt(in.readLine());
		
		
		//Apparently fast converging newton's method
		while((true)&&(c == 1)){
			
			double diff = Math.abs(aRoot - (double)(Math.pow(a, 1.0/n)));
			
			if(diff < acc){
				
				System.out.println("Root: "+ aRoot +"\nIterations: "+i);
				break;
			}
			
			aRoot = (1.0/n)*((n - 1.0)*aRoot +a/(Math.pow(aRoot, n - 1.0)));
			
			i++;
		}
		
		
	
		//normal newton's method
		//aRoot = a/2.0;
		//i  = 0;
		
		while((true)&&(c == 2)){
			
			double diff = Math.abs(aRoot - (double)Math.pow(a, 1.0/n));
			
			if(diff < acc){
				
				System.out.println("Root: "+ aRoot +"\nIterations: "+i);
				break;
			}
			
			aRoot = aRoot - (Math.pow(aRoot, n) - a)/(n*(Math.pow(aRoot, n - 1.0)));
			
			i++;
		}
		
		
		
		//System.out.println("Tot hierso werk dit");
		
		//newton's method x 5
		//aRoot = a/2.0;
		//i  = 0;
		
		while((true)&&(c == 0)){
			
			double diff = Math.abs(aRoot - (double)Math.pow(a, 1.0/n));
			
			if(diff < acc){
				
				System.out.println("Root: "+ aRoot +"\nIterations: "+i);
				break;
			}
			double x1 = aRoot, x2 = 0, x3 = 0, x4 = 0;
			
			x2 = x1 - x1/n + a/(n*(Math.pow(x1, n - 1)));
			x3 = x2 - x2/n + a/(n*(Math.pow(x2, n - 1)));
			x4 = x3 - x3/n + a/(n*(Math.pow(x3, n - 1)));
			aRoot = x4 - x4/n + a/(n*(Math.pow(x4, n - 1)));
			
			
			 
				
			i++;
		}
		
		
		
		in.read();
		
	}
	
	
	
	
}
